class FirstPage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [
                {ismode:1},
            ],
            thumburl: '',
            name: '',
            fangjianhtml:[],
            input_name:'',
            sdarr:[],
            mbkjlist:[

            ],//模板空间
            id: '0',
            partcount: 1,
            parts: [{ src: '' }, { src: '' }, { src: '' }],
            categorylist: [],
            select_swiperlink: { name: '请选择' },
            swiperimglist: [],
            input_mbname:'模板房间',
            category_select_list: [],
            recommendtablehtml: [],
            recommendlist: [],
            detail:{id:-1,name:''},
            goods_select_html: [],
            currentswipertype: 0,
            swiperlinkhtml: [],
            swipertablehtml: [],
            swiperimghtml: [],
            subtitle: '',
            totalamount:0,
            showmoban:!1,
            moban:{
                cp:[
                    {width:0,height:0,deep:0,singleprice:0}
                ],
                wj:[
                    {count:0,singleprice:0}
    
                ],
                name:'',
                amount:0
            },
            exportlist:[
                
            ],
            // exportlist1:[
            //     {
            //         room:{
            //             name:'',
            //             id:''
            //         },
            //         wjtotal:0,
            //         cptotal:0,
            //         cptotalcount:0,
            //         amount:0,
            //         wj:[{
            //             pid: '',
            //             cid: '-1',
            //             cid1: '-1',
            //             cname: '',
            //             height: "",
            //             width: "",
            //             deep: "",
            //             singleprice: 0,
            //             count: '',
            //             amount: '',
            //             unit: '',
            //             lmsm: '',
            //             mbcz: '',
            //             gtcz: '',
            //         }
                        
            //         ],
            //         cp:[
            //             {
            //                 pid: '',
            //                 cid: '-1',
            //                 cid1: '-1',
            //                 cname: '',
            //                 height: "",
            //                 width: "",
            //                 deep: "",
            //                 singleprice: 0,
            //                 count: '',
            //                 amount: '',
            //                 unit: '',
            //                 lmsm: '',
            //                 mbcz: '',
            //                 gtcz: '',

            //             }
            //         ]
            //     }
            // ],
            swiper: {
                imgs: [],
                links: []
            },
            fileimgshow: !0,
            imgstate: '',
            imgsrc: '',
            to: '',
        };
    }


    getxs(deep){
        let xs = 1;
        this.state.sdarr.forEach(x=>{
            if(deep>x.min&&deep<=x.max) xs = x.number
        })
        return xs
    }


    componentDidMount() {
        let id = GetQueryString('id'),totalamount=0, fangjianhtml = []

    //     dz_getcategorylist('XSSD',res=>{
    //         if(res.issuccess==1){
    //             this.setState({sdarr:res.list})
    //     }
    //  })

        // if(id=='null'){
        //     this.addmoban()
        // }
        dzroom_getlist(res => {
            if (res.issuccess == 1) {
                fangjianhtml.push(<option value={-1}>请选择 </option>)
                res.list.forEach((x, i) => {
                    fangjianhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })
                this.setState({ roomlist: res.list, fangjianhtml })
            }
        })

        dz_categetlist(res => {
            if (res.issuccess == 1) {
                let { list } = res

                let cate_CPLBhtml = [], cate_GTCZhtml = [], cate_WJLBhtml = [], cate_WJCZhtml = [];
                let list_CPLB = list.filter(x => x.type == 'CPLB')
                let list_GTCZ = list.filter(x => x.type == 'GTCZ')
                let list_WJLB = list.filter(x => x.type == 'WJLB')
                let list_WJCZ = list.filter(x => x.type == 'WJCZ')
                console.log({ list_CPLB, list_GTCZ, list_WJLB, list_WJCZ }, 'list1');

                cate_CPLBhtml.push(<option value={-1}>请选择 </option>)
                list_CPLB.forEach((x, i) => {
                    cate_CPLBhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                cate_GTCZhtml.push(<option value={-1}>请选择 </option>)
                list_GTCZ.forEach((x, i) => {
                    cate_GTCZhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                cate_WJLBhtml.push(<option value={-1}>请选择 </option>)
                list_WJLB.forEach((x, i) => {
                    cate_WJLBhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                cate_WJCZhtml.push(<option value={-1}>请选择 </option>)
                list_WJCZ.forEach((x, i) => {
                    cate_WJCZhtml.push(
                        <option key={i} value={x.id}>{x.name} </option>
                    )
                })

                // catehtml1.push(<option value={-1}>请选择</option>)
                // res.list1.forEach((x, i) => {
                //     catehtml1.push(
                //         <option key={i} value={x.id}>{x.name} </option>
                //     )
                // })
                this.setState({
                    cate_CPLBhtml, list_CPLB, cate_GTCZhtml, list_GTCZ, list_WJLB
                    , cate_WJLBhtml, cate_WJCZhtml, list_WJCZ
                })
            }

        })
        dz_projectdetail_getd(id,res=>{
            let detail = res.data
           // console.log(uniq(res.data.roomids.split(',')),'uniq');
            if(detail.rawData==''){
                dzroom_getlistbyid(
                    uniq(res.data.roomids.split(',')).toString(),res=>{
                        let{list} = res
                        if(list.length>0){
                            dz_getcategorylist('XSSD',res=>{
                                if(res.issuccess==1){
                                    this.setState({sdarr:res.list},()=>{
                                    list.forEach((x,i)=>{
                                        x.items.forEach((y,j)=>{
                                            list[i]['items'][j]['oindex'] = j
                                        })
                                    })

                                    console.log(list,'listlist123');

                                        this.setState({exportlist:list})
                                    })
                                    



                            }
                         })
 
                            // list.forEach(item=>{
                            //     let cptotalcount = 0,cptotal=0,wjtotal=0;
                            //     item.items.forEach(x=>{
                            //         if(x.type=='CP'){
                            //             cptotalcount+=Number(x.count)
                            //             cptotal+=(Number(x.count)*Number(x.singl eprice))
                            //         }else{
                            //             wjtotal+=(Number(x.count)*Number(x.singleprice))
                            //         }
                            //     })
                            //     item['cptotalcount']=Number(cptotalcount).toFixed(2) 
                            //     item['cptotal']=Number(cptotal).toFixed(2) 
                            //     item['wjtotal']=Number(wjtotal).toFixed(2) 
                            //     item['amount']=(Number(wjtotal)+Number(cptotal)).toFixed(2)
                            //     totalamount+=Number(wjtotal)+Number(cptotal)
                            // })
                            

                        }

                       

    
                    }
                    )
            }else{
               // console.log(),'0000');
                let exportlist = JSON.parse(decodeurl(res.data.rawData)) 

                exportlist.forEach((x,i)=>{
                    x.items.forEach((y,j)=>{
                        exportlist[i]['items'][j]['oindex'] = j
                    })
                })
                console.log(exportlist,'listlist123'); 

                this.setState({exportlist,input_name:detail.name})
            }
           // console.log(uniq(res.data.roomids.split(',')),'uniq');
             this.setState({id})
            // console.log(res,'resres');
        })

      //  $('.modal1').hide()

       // this.freshlist()

    }
    freshlist() {
        dzroom_getlist(res => {
            if (res.issuccess == 1) {
              
                // this.formatlist(res.list); 
                let roomhtml = [];
                roomhtml.push(<option value={-1}>请选择 </option>)
                res.list.forEach(x=>{
                    roomhtml.push(
                        <option value={x.id}>{x.name} </option>
                    )
                }) 
                
                this.setState({ list: res.list,roomhtml})

                console.log(res.list)
            }
        })




    }



    

    /**新建 */
    add() {
       // $('.modal1').show()
        var name = prompt('请输入房间名称')
        if (name != '') {
            aoedzroom({ name }, res => {
                if (res.issuccess == 1) {
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }
    }


    // 编辑
    edit(x) {
        var name = prompt('请编辑房间名称', x.name)
        if (name != ''&&name!=x.name) {
          //  console.log(name,'name');

          dz_projectdetail_add({ id: x.id, name }, res => {
                if (res.issuccess == 1) {
                 //   alert('修改成功')
                    this.freshlist()
                } else {
                    alert(res.msg)
                }
            })
        }

        // 
    }
    tosub(x) {
        window.location.href = "./dz_subcate.html?id=" + x.id + "&name=" + x.name;
    }
    // 排序
    addmoban(){
        if(this.state.showmoban){
            //保存
            this.savemoban()

        }else{
            let moban = {
                cp:[
                    {width:0,height:0,deep:0,singleprice:0}
                ],
                wj:[
                    {count:0,singleprice:0}
    
                ],
                name:'',
                amount:0
            }
            // let moban = {
            //     name:'123',
            //     wj:[
            //         {
            //           "count": "300",
            //           "singleprice": "15",
            //           "cid1": 84,
            //           "type": "WJ",
            //           "cname1": "国产品牌DTC铰链",
            //           "unit": "个"
            //         },
            //         {
            //           "count": "400",
            //           "singleprice": "15",
            //           "cid1": 84,
            //           "type": "WJ",
            //           "cname1": "国产品牌DTC铰链",
            //           "unit": "个"
            //         },
            //         {
            //           "count": "200",
            //           "singleprice": "48",
            //           "cid1": 113,
            //           "type": "WJ",
            //           "cname1": "文信长盒子拉手",
            //           "unit": "个"
            //         }
            //       ],
                
            //     cp:[
            //         {
            //           "width": "1000",
            //           "height": "1000",
            //           "deep": 0,
            //           "singleprice": "1000",
            //           "cid1": 78,
            //           "type": "CP",
            //           "cname1": "门板 | 柜体",
            //           "unit": "平方"
            //         },
            //         {
            //           "width": "2000",
            //           "height": "2000",
            //           "deep": 0,
            //           "singleprice": "798",
            //           "cid1": 50,
            //           "type": "CP",
            //           "cname1": "门板国产欧松板 | 柜体国产欧松板",
            //           "unit": "平方"
            //         },
            //         {
            //           "width": "3000",
            //           "height": "32000",
            //           "deep": 0,
            //           "singleprice": "880",
            //           "cid1": 41,
            //           "type": "CP",
            //           "cname1": "开放格（福人）",
            //           "unit": "平方"
            //         }
            //       ],
            // }
    
    
    
            this.setState({moban,showmoban:!0})
        }

      

       

    }
 
    addline(index,type){
        if(this.state.input_name==''){
            alert('请输入业主地址')
        }else{
            let {exportlist} = this.state,length =exportlist[index]['items'].length
           exportlist[index]['items'].push( {count:0,type,id:0,width:0,height:0,deep:0,singleprice:0,oindex:length} )
           this.setState({exportlist},()=>{
               this.save()
           })
        }
    }

    removeline(i,oi,t){
        console.log({i,oi,t},'removeline');
        let {exportlist} = this.state,items = exportlist[i]['items'];
        items.splice(oi,1)
        items.forEach((y,j)=>{
            items[j]['oindex'] = j
        })
        exportlist[i]['items'] = items
        this.setState({exportlist})

        //每次删除都要重新设置一边oindex


    //    let list = this.state.exportlist[i]['items'].filter(x=>{return x.type==t})
    //   //  let {moban} = this.state

    //     if(e==0){
    //         moban.cp.splice(i,1)
    //     }else{
    //         moban.wj.splice(i,1)
    //     }
    //     // let {moban} = this.state,data = [{}]
    //     // moban[`${e==0?'cp':'wj'}`].push(data)
    //      this.setState({moban})
    }
   
  


    // 删除
    del(e, cid) {
        this.setState({ delid: e, newcid: cid }, () => {
            $('#myModal').modal('toggle');
        })
    }

    delroom(index){
        var b = confirm('确定要删除房间吗')
        if(b){
            let {exportlist} = this.state
            exportlist.splice(index,1)
            this.setState({exportlist})
        }
    }



    confirmdel() {
        let { delid, start } = this.state
        delimg(delid, res => {
            if (res.issuccess == 1) {
              //  alert('删除成功')
                $('#myModal').modal('toggle');
                this.freshlist(start)
            } else {
                $('#myModal').modal('toggle');
                alert(res.msg);
            }
        })
    }

    closemodal() {
        $('.modal1').hide()
    }

    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    confirm() {
        let { name, subtitle } = this.state, err = '';
        if (name.length == 0) err = '请输入名称'
        dz_project_aoe({ name, subtitle }, res => {
            $('.modal1').hide()
            if (res.issuccess == 1) {
             //   alert('提交成功')
                this.freshlist()
            }
        })
    }

    toitem(id) {
        window.location.href = './dz_item.html?id=' + id
    }

    // selectchange(e){
    //     this.setState({selectroomid:e.target.value})
    // }

    selectchange(id,ei, t,index,e) {
        //  if(this.state.detail.pool!='BJ') return


        
        let { value } = e.target,{exportlist}=this.state, list = t=='GTCZ'?this.state.list_GTCZ:this.state.list_WJLB,item = list.find(x => x.id == value),i=0;
        console.log('here-selectchange',{id,ei, t, e,index,item});
        if (id>0) {
             i = exportlist[ei]['items'].findIndex(x=>{return x.id==id})
        }else{
            //自定义里的 
            // if(t=='WJLB'){
            //     index+=exportlist[ei]['items'].filter(x=>{return x.type=='CP'}).length
            // }
            i=exportlist[ei]['items'].findIndex(x=>{return x.oindex==index})
        }
        console.log(i,'selectchange--i');
        exportlist[ei]['items'][i]['cid1']=item.id;
        exportlist[ei]['items'][i]['type']=t=='GTCZ'?'CP':'WJ';
        exportlist[ei]['items'][i]['cname1']=item.name;
        exportlist[ei]['items'][i]['singleprice']=item.price;
        exportlist[ei]['items'][i]['unit']=item.unit;
        this.setState({exportlist},()=>{
            this.save()
        })
    }
    savemoban(){
        let{input_name} = this.state
        if(input_name==''){
            alert('请输入业主地址')
            return
        }else{
            let{moban,exportlist}= this.state,data = {name:this.state.input_mbname,items:[]}
            moban.cp.forEach(x=>{
                x['type'] = 'CP'
                x['id'] = -1
                data['items'].push(x)
            })
            moban.wj.forEach(x=>{
                x['type'] = 'WJ'
                x['id'] = -1
                data['items'].push(x)
            })
            exportlist.push(data)

            this.save()


            this.setState({exportlist,moban:{
                cp:[
                    {width:0,height:0,deep:0,singleprice:0}
                ],
                wj:[
                    {count:0,singleprice:0}
    
                ],
                name:'',
                amount:0
            }})
        }
    }

    selectmobanchange(index,t, e) { 
        console.log({index,t,e:e.target.value},'here-selectchange');
      //  if(this.state.detail.pool!='BJ') return
        
        let { value } = e.target,{moban}=this.state
        
       // i = exportlist[ei]['items'].findIndex(x=>{return x.id==id})



       // let { cp, wj } = this.state,data = {prop:t};
       let list = t==0?this.state.list_GTCZ:this.state.list_WJLB
        let item = list.find(x => x.id == value);
        console.log(item,'item--list');
        moban[`${t==0?'cp':'wj'}`][index] ['cid1']=item.id
        moban[`${t==0?'cp':'wj'}`][index] ['type']=t==0?'CP':'WJ';
        moban[`${t==0?'cp':'wj'}`][index] ['cname1']=item.name;
        moban[`${t==0?'cp':'wj'}`][index] ['singleprice']=item.price; 
        moban[`${t==0?'cp':'wj'}`][index] ['unit']=item.unit;
        // exportlist[ei]['items'][i]['cid1']=item.id;
        // exportlist[ei]['items'][i]['type']=t=='GTCZ'?'CP':'WJ';
        // exportlist[ei]['items'][i]['cname1']=item.name;
        // exportlist[ei]['items'][i]['singleprice']=item.price;
        // exportlist[ei]['items'][i]['unit']=item.unit;
       // console.log({item,'eitem':exportlist[ei]['items'][i]},'itemitem');
        this.setState({moban})
        // if (t == 'GTCZ') {
        //     let { list_GTCZ } = this.state, item = list_GTCZ.find(x => x.id == value);

        //     console.log({item,'eitem':exportlist[ei]['items'][i]},'itemitem');
            
        //     //  let p = list_+t
        //     // console.log(this.state[p],'gtcz');
        //     // cp[i]['cid1'] = item.id
        //     // cp[i]['cname1'] = item.name
        //     // cp[i]['singleprice'] = item.price
        //     //  additem['unit'] = item.unit
        //    // data = {id:cp[i].id,unit:item.unit,cid:item.id,name:item.name,prop:'GTCZ',price:item.price}
        // }
        // if (t == 'WJLB') {
        //     let { list_WJLB } = this.state, item = list_WJLB.find(x => x.id == value);
        //     exportlist[ei]['items'][i]=item;
        //     // wj[i]['cid'] = item.id
        //     // wj[i]['cname'] = item.name
        //     // wj[i]['unit'] = item.unit
        //   //  data = {id:wj[i].id,name:item.name,price:item.price,unit:item.unit,prop:t,cid:item.id}
        // }
       
 
    }



    export(){



        let { exportlist,detail} = this.state;

        let str = '总屋名称,'+detail.name
        //`${topname}\n${housename}\n产品类型,高,宽,深度,单价,数量,总价,单位,立面说明,门板材质/柜体材质\n`
        const jsonData = []
        let total = 0;
        let totalcount = 0;
        // <td className="tconter">{((Number(x.height)* Number(x.width))/1000000).toFixed(2)}</td>
        //                                    <td className="tconter">{(Number(x.singleprice)* (((Number(x.height)* Number(x.width))/1000000).toFixed(2))).toFixed(2)}</td>
       
        console.log(exportlist,'exportlistexportlist');  
        exportlist.forEach(x => {
            str += `\n房间名称,${x.name}\n产品类型,高,宽,深度,数量,单位,单价,总价,立面说明,门板/柜体材质\n`   
            x.items.filter(x=>{return x.type=='CP'}).forEach(y=>{
               str+= `${y.cname},${y.height},${y.width},${y.deep},${y.count},${y.unit},${y.singleprice},${(Number(y.count)*Number(y.singleprice)).toFixed(2)},${y.lmsm},${y.cname1}\n`
            })
            str+=`,,,平方总计,${x.cptotalcount},,金额合计,${x.cptotal}\n\n`

            str += `五金类型,高,宽,深度,数量,单位,单价,总价,立面说明,五金材质\n`
            x.items.filter(x=>{return x.type=='WJ'}).forEach(y=>{
                str+= `${y.cname},-,-,-,${y.count},${y.unit},${y.singleprice},${(Number(y.count)*Number(y.singleprice)).toFixed(2)},${y.lmsm},${y.cname1}\n`
             })
             str+=`,,,,,,,,金额合计,${x.wjtotal}\n`
             str+=`总金额,${Math.round(Number(x.cptotal)+Number(x.wjtotal))}\n`
             total=Math.round(Number(total)+Number(x.cptotal)+Number(x.wjtotal))
        })
         str +='\n\n总价合计,' + total
        let uri = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
        //通过创建a标签实现
        let link = document.createElement("a");
        link.href = uri;
        //对下载的文件命名
        link.download = name + ".csv";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);

    }


    addroom(){
        let {selectroomid,exportlist,totalamount} = this.state;
        if(Number(selectroomid)>0){
            dz_getprojectitemlist(selectroomid,res=>{
                if(res.issuccess==1){
                    let{room,wj,cp} =res;
                    let wjtotal = 0,cptotal=0,cptotalcount=0,wjtotalcount=0,amount=0
                    wj.forEach(x=>{
                        wjtotal= (Number(wjtotal)+(Number(x.singleprice)* Number(x.count))).toFixed(2)
                        wjtotalcount= (Number(wjtotalcount)+Number(x.count)).toFixed(2)
                    })
                    cp.forEach(x=>{
                        cptotalcount= (Number(cptotalcount)+Number(x.count)).toFixed(2)
                        cptotal= (Number(cptotal)+(Number(x.singleprice)* Number(x.count))).toFixed(2)
                    })
                    amount = (Number(wjtotal)+(Number(cptotal))).toFixed(2)
                    totalamount =(Number(totalamount)+(Number(amount))).toFixed(2)
                    let item = {room,wjtotal,cptotal,cptotalcount,wjtotalcount,amount,wj,cp}
                    console.log(item,'item');
                    exportlist.push(item)
                    console.log(exportlist,'exportlist');
                    this.setState({exportlist,totalamount})
                }
            })
        }
    }

    save(){
        let {exportlist,id,input_name}=this.state;
        if(input_name==''){
            alert('请输入业主地址')
        }else{
            let data = {name:input_name,rawData:JSON.stringify(exportlist)},{id} = this.state
            if(Number(id)>0)data['id'] = id
            dz_projectdetail_editdata(data,res=>{
                if(res.issuccess==1){
                    this.setState({id:res.id})
                    //alert('保存成功')
                    // if(ismoban){
                    //     window.location.href='./dz_newroom.html?id='+res.id
                    // }
                }
            })
        }

    }

    inputchange1(id,eindex,prop,val,tdindex,wjval){
       // if(this.state.detail.pool!='BJ') return
        var value = prompt('请输入',val)
        console.log('inputchange1',{id,eindex,prop,val});
        if (value!=val&&value != ''&& value!=null) {
            let {exportlist} = this.state
            if(id==-1){
                //自定义内容
                console.log('自定义内容',{eindex,prop,val,tdindex});
                if(wjval=='wj'){
                    tdindex+= exportlist[eindex]['items'].filter(x=>{return x.type=='CP'}).length
                   // console.log(cpcount,'cpcountcpcount');
      //  exportlist[eindex]['items'][tdindex+cpcount][prop] = value
                }

                exportlist[eindex]['items'][tdindex][prop] = value

            }else{
                let index = exportlist[eindex]['items'].findIndex(x=>{return x.id==id})
                exportlist[eindex]['items'][index][prop] = value;
            }
            this.setState({exportlist},()=>{
                this.save()
            })
            
        }
    }

    inputmobanchange1(prop,t,index,val){

        // if(this.state.detail.pool!='BJ') return
         var value = prompt('请输入',val),{moban}=this.state
         if (value!=val&&value != '') {
             let  tval = t==0?'cp':'wj'
            moban[tval][index][prop] = value;
           //  let {exportlist} = this.state,index = exportlist[eindex]['items'].findIndex(x=>{return x.id==id})
             this.setState({moban})
         }
     }

 


    selectfang(e) { 
        console.log(e.target.value,'edddd');
        let sel_fang = e.target.value
        this.setState({sel_fang}) 
    }

    addfangjian(){
        let {sel_fang,exportlist} = this.state;
        dzroom_getlistbyid( sel_fang,res=>{
                            let{list} = res
                            if(list.length>0){
                                list.forEach(item=>{
                                    let cptotalcount = 0,cptotal=0,wjtotal=0;
                                    item.items.forEach(x=>{
                                        if(x.type=='CP'){
                                            cptotalcount+=Number(x.count)
                                            cptotal+=(Number(x.count)*Number(x.singleprice))
                                        }else{
                                            wjtotal+=(Number(x.count)*Number(x.singleprice))
                                        }
                                    })
                                    item['cptotalcount']=Number(cptotalcount).toFixed(2) 
                                    item['cptotal']=Number(cptotal).toFixed(2) 
                                    item['wjtotal']=Number(wjtotal).toFixed(2) 
                                    item['amount']=(Number(wjtotal)+Number(cptotal)).toFixed(2)
                                  //  totalamount+=Number(wjtotal)+Number(cptotal)
                                    exportlist.push(item)
                                })

                                console.log(exportlist,'addfangjian');

                                this.setState({exportlist})

    }
})
}




    render() {
        var {input_name,sel_fang,fangjianhtml, moban,showmoban,input_mbname, detail,name,exportlist,totalamount, cate_WJLBhtml,roomhtml,selectroomid,cate_GTCZhtml } = this.state;
        console.log(moban,'moban');

        let moban_amount = 0;
        moban.cp.forEach(x=>{
            moban_amount+=Math.round(((Number(x.height) * Number(x.width)) / 1000000)*Number(x.singleprice))
        })
        moban.wj.forEach(x=>{
            moban_amount+=Math.round(Number(x.count)*Number(x.singleprice))
        })
        moban.amount = moban_amount
        console.log(exportlist,'exportlistexportlist');

        if(exportlist.length>0){
            exportlist.forEach(item=>{
                let cptotalcount = 0,cptotal=0,wjtotal=0;
                item.items.forEach(x=>{
                   
                    if(x.type=='CP'){
                        x.count =   (x.unit=='米'? (Number(x.deep)/1000):((Number(x.height) * Number(x.width)) / 1000000))*this.getxs(x.deep)
                        cptotalcount+=Number(x.count)
                        cptotal= Math.round(Number(cptotal)+(Number(x.count)*Number(x.singleprice)))
                    }else{
                        wjtotal= Math.round(Number(wjtotal)+(Number(x.count)*Number(x.singleprice)))
                    }
                })
                item['cptotalcount']=Number(cptotalcount).toFixed(2) 
                item['cptotal']=cptotal 
                item['wjtotal']=wjtotal
                item['amount']=Math.round(Number(wjtotal)+Number(cptotal))
                totalamount= Math.round(Number(totalamount)+Number(wjtotal)+Number(cptotal))
            })
        }
        return (
          
            <div className="breadLinebox">

<div className="content">
                            <input placeholder="请输入业主地址" allowClear value={input_name} onChange={this.inputchange.bind(this, 'input_name')} className="input" />
                        </div>

                        <div className="selfang">
                        <p className="p1">选择房型</p>
                        <select value={sel_fang} onChange={this.selectfang.bind(this)}>  {fangjianhtml} </select>
                        <p onClick={this.addfangjian.bind(this)} className="btn">添加房型</p>
                        <p onClick={this.savemoban.bind(this)} className="btn">新增房间</p>
                    </div>



                <div className='content_wrap panel-default content_wrap'>
                    {/* <div onClick={()=>{window.location.href='./dz_cate.html'}} className='breadLine '>
                        前往分类管理
                    </div> */}
                    {/* <div className='inputs panel-body'>
                        <h3>首页管理</h3>
                    </div> */}
                    {/* <div className="back" onClick={()=>{window.location.href='./dz_main.html'}}>返回</div> */}

                    {
                        showmoban?
                        <div className="content form">
                            <div className="vv">
                            <input placeholder="请输入房间名称" allowClear value={input_mbname} onChange={this.inputchange.bind(this, 'input_mbname')} className="input" />
                            {/* <div onClick={this.savemoban.bind(this)} className="btn">保存模板</div> */}
                            </div>
                        <div>
                                        
                                          <div className="content form">
                                          <p>{moban.name}</p>
                                        
                                          < table className="tab">
                                              <thead>
                                                  <tr>
                                                      {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}
                  
                                                      <th className="tconter">序号</th>
                                                      <th className="tconter w80">产品类型</th>
                                                      <th className="cz tconter">宽度</th>
                                                      <th className="tconter">高度</th>
                                                      <th className="cz tconter">深度</th>
                                                      <th className="cz tconter">数量</th>
                                                      <th className="cz tconter">单位</th>
                                                      <th className="cz tconter">单价</th>
                                                      <th className="cz tconter">总价</th>
                                                      <th className="cz tconter w80">立面说明</th>
                                                      <th className="cz tconter w80">门板/柜体材质</th>
                                                      <th className="cz tconter">操作</th>
                                                  </tr>
                                              </thead>
                                              <tbody>
                                                  {
                                                      
                                                      moban.cp.map((item_cp, index) => {
                                                          return (
                                                              <tr key={index}>
                                                                  {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                  {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                                  <td className="tconter">{index + 1}</td> 
                                                                  <td onClick={this.inputmobanchange1.bind(this,'cname',0,index,item_cp.cname)} className="tconter w80">
                                                                  {item_cp.cname}
                                                                  </td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'width',0,index,item_cp.width)} className="tconter">{item_cp.width}</td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'height',0,index,item_cp.height)} className="tconter">{item_cp.height}</td>
                                                                  <td  onClick={this.inputmobanchange1.bind(this,'deep',0,index,item_cp.deep)} className="tconter">{item_cp.deep}</td>
                                                                  <td className="tconter">{((Number(item_cp.height) * Number(item_cp.width)) / 1000000).toFixed(2)}</td>
                                                                  {/* <td className="tconter">{item_cp.unit}</td>  */}
                                                                  <td  onClick={this.inputmobanchange1.bind(this,'unit',0,index,item_cp.unit)} className="tconter">{item_cp.unit}</td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'singleprice',0,index,item_cp.singleprice)} className="tconter">{item_cp.singleprice}</td>
                                                                  <td className="tconter">{Math.round(Number(item_cp.singleprice) * Number(((Number(item_cp.height) * Number(item_cp.width)) / 1000000)))}</td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'lmsm',0,index,item_cp.lmsm)} className="tconter w80">{item_cp.lmsm}</td>
                                                                  {/* <td className="tconter w80"> {item_cp.cname1}</td> */}
                                                                  <td className="tconter">
                                          <select value={item_cp.cid1} onChange={this.selectmobanchange.bind(this,index,0)}>  {cate_GTCZhtml} </select>
                                      </td>
                                      <td   className="tconter w80 btn ">
                                        <p onClick={this.addline.bind(this,0)}>添加一行</p>
                                        <p style={{display:index>0?'':'none'}} onClick={this.removeline.bind(this,0,index)}>移除</p>
                                        </td>
                                                               </tr>
                                                          )
                  
                                                      })
                                                  }
                                              </tbody>
                                          </table>
                                          {/* <div className="tongji">
                                              <div>
                                              <p> 数量合计：{x.cptotalcount}</p>
                                              <p> 合计：{x.cptotal}</p>
                                              </div>
                                                  
                                             
                                          </div> */}


                                          <table className="tab">
                                              <thead>
                                                  <tr>
                                                      {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}
                  
                                                      <th className="tconter">序号</th>
                                                      <th className="tconter w80">五金类别</th>
                                                      <th className="cz tconter">宽度</th>
                                                      <th className="tconter">高度</th>
                                                      <th className="cz tconter">深度</th>
                                                      <th className="cz tconter">数量</th>
                                                      <th className="cz tconter">单位</th>
                                                      <th className="cz tconter">单价</th>
                                                      <th className="cz tconter">总价</th>
                                                      <th className="cz tconter w80">立面说明</th>
                                                      <th className="cz tconter w80" >备注</th>
                                                      <th className="cz tconter w80" >操作</th>
                                                  </tr>
                                              </thead>
                                              <tbody>
                                                  {
                                                      moban.wj.map((item_cp, i) => {
                                                          return (
                                                              <tr key={i}>
                                                                  {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                  {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */} 
                                                                  <td className="tconter">{i + 1}</td>
                                                                  {/* <td className="tconter w80">
                                                                  {item_cp.cname1}
                                                                  </td> */}
                                                                  <td className="tconter">
                                                                  <select value={item_cp.cid1} onChange={this.selectmobanchange.bind(this, i,1)}>  {cate_WJLBhtml} </select> 
                                          
                                      </td>
                                                                  <td  className="tconter">-</td>
                                                                  <td  className="tconter">-</td>
                                                                  <td  className="tconter">-</td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'count',1,i,item_cp.count)} className="tconter">{item_cp.count}</td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'unit',1,i,item_cp.unit)} className="tconter">{item_cp.unit}</td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'singleprice',1,i,item_cp.singleprice)} className="tconter">{item_cp.singleprice}</td>
                                                                  <td className="tconter">{ Math.round(Number(item_cp.singleprice) * Number(item_cp.count))}</td>
                                                                  <td onClick={this.inputmobanchange1.bind(this,'lmsm',1,i,item_cp.lmsm)} className="tconter w80">{item_cp.lmsm}</td>
                                                                  <td className="tconter w80"> {item_cp.cname}</td>
                                                                  <td   className="tconter w80 btn ">
                                        <p onClick={this.addline.bind(this,i,'CP')}>添加一行</p>
                                        <p style={{display:i>0?'':'none'}} onClick={this.removeline.bind(this,1,i)}>移除</p>
                                        </td>
                                                              </tr>
                                                          )
                  
                                                      })
                                                  }
                                              </tbody>
                                          </table>
                                          {/* <div className="tongji">
                                              <div>
                                              <p> 合计：{x.wjtotal}</p>
                                              </div>

                                          </div> */}
                                          <div className="tongji he">
                                              <p>合计金额：{moban.amount||0}</p>
                                          </div>
                                          
                                      </div>
                                      </div>



                  </div>
                        :null
                    }
                   


                    
                    <div className="content form">
                        {/* <div style={{display:clicknew?"":"none"}} id="div"> */} 
                        <div className="titlet">{this.state.detail.name}</div>
                        {
                         exportlist.map((x, exportindex) => { 
                                        return (
                                            <div>
                                          
                                            <div className="content form">
                                            <div className="deldiv">
                                            <p>{x.name}</p>
                                            <p onClick={this.delroom.bind(this,exportindex)} className="delroom">删除</p>
                                            </div>
                                            <table className="tab">
                                                <thead>
                                                    <tr>
                                                        {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}
                    
                                                        <th className="tconter">序号</th>
                                                        <th className="tconter w80">产品类型</th>
                                                        <th className="cz tconter">宽度</th>
                                                        <th className="tconter">高度</th>
                                                        <th className="cz tconter">深度</th>
                                                        <th className="cz tconter">数量</th>
                                                        <th className="cz tconter">单位</th>
                                                        <th className="cz tconter">单价</th>
                                                        <th className="cz tconter">总价</th>
                                                        <th className="cz tconter w80">立面说明</th>
                                                        <th className="cz tconter w80">门板/柜体材质</th>
                                                        <th className="cz tconter">操作</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    {
                                                        
                                                        x.items.filter(x=>{return x.type=='CP'}).map((item_cp, index) => {
                                                            let count = (item_cp.unit=='米'? (Number(item_cp.deep)/1000):((Number(item_cp.height) * Number(item_cp.width)) / 1000000))*this.getxs(item_cp.deep)

                                                            return (
                                                                <tr key={index}>
                                                                    {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                    {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                                    <td className="tconter">{index + 1}</td>
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'cname',item_cp.cname,index)} className="tconter w80">
                                                                    {item_cp.cname}
                                                                    </td>
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'width',item_cp.width,index)} className="tconter">{item_cp.width}</td>
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'height',item_cp.height,index)} className="tconter">{item_cp.height}</td>
                                                                    <td  onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'deep',item_cp.deep,index)} className="tconter">{item_cp.deep}</td>
                                                                    <td className="tconter">{
                                                                    count.toFixed(2)}</td>
                                                                    <td className="tconter">{item_cp.unit}</td> 
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'singleprice',item_cp.singleprice,index)} className="tconter">{item_cp.singleprice}</td>
                                                                    <td className="tconter">{Math.round(Number(item_cp.singleprice) * count)}</td>
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'lmsm',item_cp.lmsm,index)} className="tconter w80">{item_cp.lmsm}</td>
                                                                    {/* <td className="tconter w80"> {item_cp.cname1}</td> */}
                                                                    <td className="tconter">
                                            <select value={item_cp.cid1} onChange={this.selectchange.bind(this, item_cp.id,exportindex, 'CP',item_cp.oindex)}>  {cate_GTCZhtml} </select>
                                        </td>
                                        <td   className="tconter w80 btn ">
                                        <p onClick={this.addline.bind(this,exportindex,'CP')}>添加一行</p>
                                        <p  onClick={this.removeline.bind(this,exportindex,item_cp.oindex,'CP')}>移除</p>
                                        </td>
                                        
                                                                </tr>
                                                            )
                    
                                                        })
                                                    }
                                                </tbody>
                                            </table>
                                            {/* <div className="tongji">
                                                <div>
                                                <p> 数量合计：{x.cptotalcount}</p>
                                                <p> 合计：{x.cptotal}</p>
                                                </div>
                                                    
                                               
                                            </div> */}


                                            <table className="tab">
                                                <thead>
                                                    <tr>
                                                        {/* <th className="minwidth tconter"><img src="./src/notselection.png"/></th> */}
                    
                                                        <th className="tconter">序号</th>
                                                        <th className="tconter w80">五金类别</th>
                                                        <th className="cz tconter">宽度</th>
                                                        <th className="tconter">高度</th>
                                                        <th className="cz tconter">深度</th>
                                                        <th className="cz tconter">数量</th>
                                                        <th className="cz tconter">单位</th>
                                                        <th className="cz tconter">单价</th>
                                                        <th className="cz tconter">总价</th>
                                                        <th className="cz tconter w 80">立面说明</th>
                                                        <th className="cz tconter w80" >备注</th>
                                                        <th className="cz tconter">操作</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    {
                                                        x.items.filter(x=>{return x.type=='WJ'}).map((item_cp, i) => {
                                                            return (
                                                                <tr key={i}>
                                                                    {/* <td className="minwidth tconter"><img src="./src/notselection.png"/></td>  */}
                                                                    {/* <td className="tconter">{x.state=="0"?"显示":"隐藏"}</td>  */}
                                                                    <td className="tconter">{i + 1}</td>
                                                                    {/* <td className="tconter w80">
                                                                    {item_cp.cname1}
                                                                    </td> */}
                                                                    <td className="tconter">
                                                                    <select value={item_cp.cid1} onChange={this.selectchange.bind(this, item_cp.id,exportindex, 'WJ',item_cp.oindex)}>  {cate_WJLBhtml} </select> 
                                            
                                        </td>
                                                                    <td  className="tconter">-</td>
                                                                    <td  className="tconter">-</td>
                                                                    <td  className="tconter">-</td>
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'count',item_cp.count,i,'wj')} className="tconter">{item_cp.count}</td>
                                                                    <td className="tconter">{item_cp.unit}</td>
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'singleprice',item_cp.singleprice,i,'wj')} className="tconter">{item_cp.singleprice}</td>
                                                                    <td className="tconter">{ Math.round(Number(item_cp.singleprice) * Number(item_cp.count))}</td>
                                                                    <td onClick={this.inputchange1.bind(this,item_cp.id,exportindex,'lmsm',item_cp.lmsm,i,'wj')} className="tconter w80">{item_cp.lmsm}</td>
                                                                    <td className="tconter w80"> {item_cp.cname}</td>
                                                                    <td   className="tconter w80 btn ">
                                        <p onClick={this.addline.bind(this,i,'WJ')}>添加一行</p>
                                        <p onClick={this.removeline.bind(this,i,'WJ')}>移除</p>
                                        </td>
                                                                </tr>
                                                            )
                    
                                                        })
                                                    }
                                                </tbody>
                                            </table>
                                            {/* <div className="tongji">
                                                <div>
                                                <p> 合计：{x.wjtotal}</p>
                                                </div>

                                            </div> */}
                                            <div className="tongji he">
                                                <p>合计金额：{x.amount}</p>
                                            </div>
                                            
                                        </div>
                                        </div>

                                        )
                                    })
                                }


<div className="tabletit" >

{/* <select value={selectroomid} onChange={this.selectchange.bind(this)}>{roomhtml} </select>

    <p className="add" style={{'cursor':'pointer'}} onClick={this.addroom.bind(this)}>添加</p> */}

   <p>总金额：{totalamount}</p>
   <div>
    <p className="add" style={{'cursor':'pointer'}} onClick={this.export.bind(this)}>导出</p>
    <p className="add" style={{'cursor':'pointer'}} onClick={this.save.bind(this)}>保存</p>
    <p className="add" style={{'cursor':'pointer'}} onClick={()=>{window.location.href='./dz_main.html'}}>返回</p>
   </div>
</div>
 


                    </div>

                </div >


            </div >

            
        )
    }
}





ReactDOM.render(
    <div>
        {/* <LeftMenu code='0' /> */}
        <FirstPage />
    </div>
    //<Barrage/>
    , $('.container')[0]
)